#ifndef     __EVENT_FLAGS_H
#define     __EVENT_FLAGS_H

#include "../rtx/rtx_os.h"

namespace rtos {

class EventFlags {

public:
    EventFlags(const char *name = "other") {
        osEventFlagsAttr_t attr;
        attr.name = name;
        attr.attr_bits = 0;
        attr.cb_mem = m_cb_mqm;
        attr.cb_size = osRtxEventFlagsCbSize;
        m_id = osEventFlagsNew(&attr);
    }

    inline uint32_t wait_any(uint32_t flags, uint32_t timeout = osWaitForever) {
        return osEventFlagsWait(m_id, flags, osFlagsWaitAny, timeout);
    }

    inline uint32_t set_flags(uint32_t flags) {
        return osEventFlagsSet(m_id, flags);
    }

    inline uint32_t clr_flags(uint32_t flags) {
        return osEventFlagsClear(m_id, flags);
    }

private:
    osEventFlagsId_t m_id;
    uint64_t m_cb_mqm[ (osRtxEventFlagsCbSize + 7) / 8 ];
};

}

#endif
